package com.hunttown.mes.dao;

import com.hunttown.common.dao.base.BaseDao;
import com.hunttown.common.domain.Query;
import com.hunttown.mes.domain.TransportUserCardLog;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Repository;

import java.util.List;
import java.util.Map;

/**
 * created by wangjunfu on 2021-02-24 16:00:13
 */
@Repository
public class TransportUserCardLogDao extends BaseDao {
    private static final Logger logger = LoggerFactory.getLogger(TransportUserCardLogDao.class);

    public TransportUserCardLog insert(final TransportUserCardLog transportUserCardLog) {
        insert("TransportUserCardLog.insert", transportUserCardLog);
        return transportUserCardLog;
    }

    public Boolean updateInfoById(final TransportUserCardLog transportUserCardLog) {
        return update("TransportUserCardLog.updateInfoById", transportUserCardLog) > 0;
    }

    public Boolean updateInfoByQuery(final Query query) {
        return update("TransportUserCardLog.updateInfoByQuery", query) > 0;
    }

    public TransportUserCardLog selectById(final Integer id, final Integer entId) {
        Query query = Query.noPage();
        query.put("id", id);
        query.put("entId", entId);
        return queryForObject("TransportUserCardLog.selectById", query);
    }

    public TransportUserCardLog selectByOrderIdForApi(final String orderId) {
        Query query = Query.noPage();
        query.put("orderId", orderId);
        return queryForObject("TransportUserCardLog.selectByOrderIdForApi", query);
    }

    public List<TransportUserCardLog> selectByQuery(final Query query) {
        return queryForList("TransportUserCardLog.selectByQuery", query);
    }

    public Long countByQuery(final Query query) {
        return queryForObject("TransportUserCardLog.countByQuery", query);
    }

    public Boolean deleteById(final Integer id, final Integer entId) {
        TransportUserCardLog transportUserCardLog = new TransportUserCardLog();
        transportUserCardLog.setDeleteFlag(1);
        transportUserCardLog.setId(id);
        transportUserCardLog.setEntId(entId);

        return update("TransportUserCardLog.updateInfoById", transportUserCardLog) > 0;
    }

    //物理删除不可恢复，慎用！
    public Boolean deleteByIdForPhysical(final Integer id) {
        Query query = Query.noPage();
        query.put("id", id);
        return delete("TransportUserCardLog.deleteById", query) > 0;
    }

    //计算某个设备，一天的总费用
    public Float computeTotalAmount(final Query query) {
        return queryForObject("TransportUserCardLog.computeTotalAmount", query);
    }

    //以map的形式返回数据
    public List<Map<String, String>> getMapDataByQuery(final Query query, final String element) {
        return queryForList("TransportUserCardLog." + element, query);
    }
}